/*
 * GraficaRuffiny.java
 *
 * Created on 3 de julio de 2009, 20:58
 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/**
 *
 * @author  USER
 */
public class GraficaRuffiny extends JFrame {
    Coord PC=new Coord(50);
    // Variables Grado de funcion y Tamaño del vector
    int grado, gradomaximo;
    // Variables Rango de Tabla
    int xinicial, xfinal;
    //
    // Variables Funcion
    int vector[];
    int vectorcoeficiente[];
    int x;
    int datoentrante;
    int tamañovector;
    int c = 0;
    int g = 0;
    int Fx = 0;
    double Fx2 = 0;
    int y = 0;
    int vectorfuncion[];
    double vectorfunciongraf[];
    int tamañograf;
    String xcoordenada[];
    String ycoordenada[];
    String subx[];
    String suby[];
    public GraficaRuffiny() {
        initComponents();
        //Propiedades del Plano
        PC.setBackground(Color.white);
        PC.setBounds(new Rectangle(314,5,700,700));        
        PC.Limites(20, 20, -20, -20);
        PC.Origen();
        add(PC);
        // Desabilitar algunos objetos
        textField2.setEnabled(false);
        textField3.setEnabled(false);
        textField4.setEnabled(false);
        textField1.requestFocus();
        jButton4.setEnabled(false);
        jButton2.setEnabled(false);
        // dESABILITAR Lista para GraFICA
        list4.setVisible(false);
        list4.setEnabled(false);
        list5.setVisible(false);
        list5.setEnabled(false);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        textField2 = new java.awt.TextField();
        jLabel3 = new javax.swing.JLabel();
        textField1 = new java.awt.TextField();
        jLabel2 = new javax.swing.JLabel();
        list1 = new java.awt.List();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        textField4 = new java.awt.TextField();
        jLabel4 = new javax.swing.JLabel();
        textField3 = new java.awt.TextField();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        jPanel3 = new javax.swing.JPanel();
        list2 = new java.awt.List();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        list3 = new java.awt.List();
        list4 = new java.awt.List();
        list5 = new java.awt.List();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(153, 51, 0));

        jPanel1.setBackground(new java.awt.Color(102, 255, 255));

        textField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textField2KeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Coeficiente");

        textField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textField1KeyTyped(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Grado");

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Valor inicial de x");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Valor final de x");

        textField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textField3KeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4))
                .addGap(34, 34, 34)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(textField4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textField3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(textField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(121, 121, 121))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(list1, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
        );

        label1.setBackground(new java.awt.Color(255, 255, 255));

        label2.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(51, 255, 153));

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("x");

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("y");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(list2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(list3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(list3, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(list2, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
                .addContainerGap())
        );

        jButton2.setText("Funcion");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton4.setText("Graficar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton1.setText("Nuevo");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Salir");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton4)
                        .addGap(29, 29, 29)
                        .addComponent(jButton3))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton1)
                                        .addGap(29, 29, 29)
                                        .addComponent(jButton2))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(label2, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(list4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(list5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(471, 471, 471)))
                .addGap(243, 243, 243))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jButton4))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jButton3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(list4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(list5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(100, 100, 100))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void textField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textField2KeyTyped
        // TODO add your handling code here: 

        vector = new int [gradomaximo];
        vectorcoeficiente = new int[gradomaximo];
        char caracter = evt.getKeyChar();
        if (((caracter < '0') ||
                (caracter > '9')) && (caracter != '-') &&
                (caracter != KeyEvent.VK_BACK_SPACE)) {
            evt.consume();
        }
        if (caracter == KeyEvent.VK_ENTER) {
            if ((textField2.getText().equals(""))||(textField2.getText().equals("-")))
            {
            JOptionPane.showMessageDialog(null, "Llene la casilla!!!", "Ventana Error Datos", JOptionPane.ERROR_MESSAGE); 
            }
            else
            {

            x = x - 1;
            if (x > -1) {
            datoentrante = Integer.parseInt(String.valueOf(textField2.getText()));
            tamañovector = vector.length;
                for (int e = c; e < tamañovector; e++) 
                {
                    vector[e] = datoentrante;
                    if (x==grado)
                    {
                        label1.setText("F(x)=");
                        label2.setText(String.valueOf(vector[e]+"("+"x^"+x+")"));
                        //vectorcoeficiente[c]=numeroingresado;
                    } 
                    else 
                    {
                        if (vector[e] >= 0) {
                            label2.setText(String.valueOf(label2.getText() + "+" + vector[e] + "("+ "x^"+x +")"));
                        } 
                        else if(vector[e] < 0)
                        {
                            label2.setText(String.valueOf(label2.getText() + vector[e] + "("+ "x^"+x+")"));
                        }
                        e = tamañovector;
                        c = c + 1;
                    }
                }
                if (x != 0) 
                {
                    textField2.setText("");
                } 
                else 
                {
                    textField2.setText("");
                    textField2.setEnabled(false);
                    textField3.setEnabled(true);
                    textField3.requestFocus();
                }
            }
            else 
            {
                textField2.setEnabled(false);
                textField3.setEnabled(true);
                textField3.requestFocus();
            }
            
            for ( int j = g; j <grado+1; j++) {
                vector[j] = datoentrante;
                j=grado+1;
            }
            vectorcoeficiente [g] = datoentrante;
            for (int lis=g ;lis<gradomaximo;lis++) {
                String item2 = String.valueOf( vectorcoeficiente[lis]);
                list1.add(item2);
                lis=gradomaximo;
            }
            g=g+1;
            
            }
            
        }
            
    }//GEN-LAST:event_textField2KeyTyped

    private void textField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textField1KeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0') ||
                (caracter > '9')) &&
                (caracter != KeyEvent.VK_BACK_SPACE)) {
            evt.consume();
        }
        
        if (caracter == KeyEvent.VK_ENTER) {
            try{
                grado = Integer.parseInt(textField1.getText());
                if ((grado>0)&&(grado<10)) {
                    gradomaximo = grado + 1;
                    x = gradomaximo;
                    textField1.setEnabled(false);
                    textField2.setEnabled(true);
                    textField2.requestFocus();
                } else {
                    JOptionPane.showMessageDialog(null,"Rango de Grados 1-9");
                    textField1.setText("");
                    
                }
            }//fin del try
            catch (Exception e ) {
                JOptionPane.showMessageDialog(null,"¡Error! Ingrese Valores");
            }
        }
    }//GEN-LAST:event_textField1KeyTyped

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        textField1.requestFocus();
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        textField1.setText("");
        PC.Reiniciar();
        list1.removeAll();
        list2.removeAll();
        list3.removeAll();
        list4.removeAll();
        list5.removeAll();
        textField1.setEnabled(true);
        textField2.setEnabled(false);
        textField3.setEnabled(false);
     jButton4.setEnabled(false);
     jButton2.setEnabled(false);
         textField2.setText("");
         textField3.setText("");
         textField4.setText("");
         label1.setText("");
         label2.setText("");
         grado=0;
         gradomaximo=0;
         x=0;
         datoentrante=0;
         tamañovector=0;
         c = 0;
         g=0;
        Fx=0;

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButton3MouseClicked

    private void textField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textField3KeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0') ||
                (caracter > '9')) && (caracter > '-') &&
                (caracter != KeyEvent.VK_BACK_SPACE)) {
            evt.consume();
        }
        if (caracter == KeyEvent.VK_ENTER) {
            try{
                xinicial = Integer.valueOf(textField3.getText());
                if ((xinicial>-6)&&(xinicial<-2)) {
                    textField3.setEnabled(false);
                    xfinal=xinicial*-1;
                    textField4.setText(String.valueOf(xfinal));
                    textField4.setEnabled(false);
                     jButton2.setEnabled(true);
                } else {
                    JOptionPane.showMessageDialog(null,"Rangode X inicial,Ingrese Numero Negativo");
                    textField3.setText("");
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null,"¡Error! Ingrese Valor");
            }
        }
    }//GEN-LAST:event_textField3KeyTyped

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
       
        vectorfuncion=new int [gradomaximo];
        vectorfunciongraf=new double [gradomaximo];
        for (int i = xinicial; i <= xfinal; i=i+1) {
            String item = String.valueOf(i);
            list2.add(item);
        }
        //Valores Para Graficar Punto X.
        for (double i2 = xinicial; i2 < xfinal+0.01; i2=(double) (i2 + 0.01)) {
            String item = String.valueOf(i2);
            list4.add(item);
        }
        String valorx[]=list4.getItems();
        tamañograf=valorx.length;
        //
        String cadena[] = list1.getItems();
        if( cadena.length != 0 ) {
            for( int f=0; f < cadena.length; f++ ){
               // JOptionPane.showMessageDialog(null,"items ingresados"+cadena[f]);
                vectorfuncion[f]=Integer.parseInt(String.valueOf(cadena[f]));
            }
        }
        for (int a = xinicial; a <= xfinal; a=a+1) {
            Fx= vectorfuncion[0];
           // JOptionPane.showMessageDialog(null,"items ingresados"+vectorfuncion[0]);
            
            for (int b = 1; b <= grado; b=b+1) {
               
                Fx= (Fx*a)+vectorfuncion[b];
                
            }
            String item = String.valueOf(Fx);
            list3.add(item);
        } 
        //Valores Para Graficar Punto Y.
        String puntos[] = list1.getItems();
        if( puntos.length != 0 ) {
            for( int f2=0; f2 < puntos.length; f2++ ){
               // JOptionPane.showMessageDialog(null,"items ingresados"+cadena[f2]);
                vectorfuncion[f2]=Integer.parseInt(String.valueOf(cadena[f2]));
            }
        }
        for (double a = xinicial; a < xfinal+0.01; a=(double) (a + 0.01)) {
            Fx2= vectorfuncion[0];
            //JOptionPane.showMessageDialog(null,"items ingresados"+vectorfuncion[0]);
            
            for (int b = 1; b <= grado; b=b+1) {
            Fx2= (Fx2*a)+vectorfuncion[b];
            }
            String item = String.valueOf(Fx2);
            list5.add(item);
        } 
        
        jButton2.setEnabled(false);
        
        
     jButton4.setEnabled(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        Calcular(evt);
    }//GEN-LAST:event_jButton4ActionPerformed
    public void Calcular(ActionEvent evt)
      {
       int m ;
       String puntox[] = list4.getItems();
       String puntoy[] = list5.getItems();
      // JOptionPane.showMessageDialog(null,"tamaño del vector"+tamañograf);
       xcoordenada =new String [tamañograf];
       ycoordenada =new String [tamañograf];
       subx =new String [9];
       suby =new String [9];
       for( m=0; m < puntox.length; m++ )
           {
            xcoordenada[m]=String.valueOf(puntox[m]);
           // JOptionPane.showMessageDialog(null,"valoresen x="+xcoordenada[j]);
           } 
       for( m=0; m < puntoy.length; m++ )
           {
           
            ycoordenada[m]=String.valueOf(puntoy[m]);
            //JOptionPane.showMessageDialog(null,"valoresen y="+ycoordenada[j]);
           }
       for( m=0 ; m< puntox.length;m++){
      
        PC.Punto(Double.parseDouble(xcoordenada[m]),Double.parseDouble(ycoordenada[m]));
        PC.repaint();
        } 
        jButton4.setEnabled(false);
      }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GraficaRuffiny().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.List list1;
    private java.awt.List list2;
    private java.awt.List list3;
    private java.awt.List list4;
    private java.awt.List list5;
    private java.awt.TextField textField1;
    private java.awt.TextField textField2;
    private java.awt.TextField textField3;
    private java.awt.TextField textField4;
    // End of variables declaration//GEN-END:variables
    
}
